package cn.com.pajx.pajx_visitor_v3.base;

import androidx.fragment.app.Fragment;

/**
 * A simple {@link Fragment} subclass.
 * create an instance of this fragment.
 */
public abstract class BaseMvpLazyFragment<B extends BasePresenter> extends BaseFragment {
    protected B mPresenter;

    protected boolean isVisible;//是否可见

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (getUserVisibleHint()) {
            isVisible = true;
            onVisible();
        } else {
            isVisible = false;
            onInvisible();
        }
    }

    protected void onVisible() {
        mPresenter = initPresenter();
        mPresenter.attach(this);
        lazyLoad();
    }

    protected abstract void lazyLoad();

    protected void onInvisible() {
    }

    @Override
    protected void beforeInitHead() {

    }

    protected abstract B initPresenter();

    @Override
    public void onDestroy() {
//        mPresenter.detach();
        //mPresenter.unSubscribe();
        super.onDestroy();
    }

}
